package com.gcu.drivingschool.task;

import com.gcu.drivingschool.domain.po.BookDriving;
import com.gcu.drivingschool.service.BookDrivingService;
import com.gcu.drivingschool.service.BookExamService;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.util.List;

/**
 * 定期检查预约记录
 * @author zzr
 * @create 2024-04-07-22:48
 */
@Component
@RequiredArgsConstructor
public class CheckReservationRecordTask {
    private final BookDrivingService bookDrivingService;
    private final BookExamService bookExamService;

    @Scheduled(cron = "10 0 0 * * ?")//每天0点检查
    public void checkReservationRecord(){
        //查询未过期记录
        List<BookDriving> bookDrivingList = bookDrivingService.lambdaQuery()
                        .ne(BookDriving::getStatus,"已过期").list();

        for (BookDriving d : bookDrivingList) {
            if (LocalDate.now().isAfter(d.getBookDate())) {
                d.setStatus("已过期");
                bookDrivingService.updateById(d);
            }
        }

    }


}
